import { getAll } from '@/api/site'
import { getAddress, setAddress, removeAddress } from '@/utils/auth'
const address = {
  state: () => ({
    addressInfo: getAddress()
  }),
  mutations: {
    setAddressInfo(state, data) {
      state.addressInfo = data
      setAddress(data)
    },
  },
  actions: {
    async getAddressInfo(context) {
      const { data } = await getAll()
      context.commit('setAddressInfo', data)
    },

  },
  getters: {
    getaddress(state) {
      const options = []
      state.addressInfo.forEach((e, index) => {
        options.push({
          value: e.id,
          label: e.site,
        })
      });

      return options
    }
  },
  namespaced: true,
}
export default address